import time

def show_info():
    print('请输入提示数字,执行相应操作:0.退出 1.查看登录日志')

# 记录登录日志
def write_loginfo(username):
    with open('log.txt', 'a') as file:
        s = '用户名:{0},登录时间:{1}\n'.format(username, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
        file.write(s)

# 读取日志的函数
def read_loginfo():
    with open('log.txt', 'r') as file:
        while True:
            line = file.readline()
            if line == '':
                break
            else:
                print(line)

# 输入用户名和密码进行登录
username = input('请输入用户名:')
pwd = input('请输入密码:')
if username == 'admin' and pwd == 'admin':
    print('登录成功')
    # 调用函数 写入日志
    write_loginfo(username)
    # 提示信息
    show_info()
    num = eval(input('请输入操作数字:'))
    while True:
        if num == 0:
            print('退出成功')
            break
        elif num == 1:
            print('查看登录日志')
            read_loginfo()
            show_info()
        else:
            print('您输入的数字有误!')
            show_info()
        num = eval(input('请输入操作数字:'))
else:
    print('用户名或密码不正确')
